home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / MyScan.p < prev    next >
Encoding:
Text File  |  1996-08-24  |  1.6 KB  |  77 lines  |  [TEXT/CWIE]

  1. unit MyScan;
  2.  
  3. interface
  4.  
  5. *** moved to MyFileSystemUtils ***
  6.  
  7.     uses
  8.         Files;
  9.     
  10.     type
  11.         ScanProc = function(var fs:FSSpec; folder:boolean; path:Str255; var pb:CInfoPBRec):boolean;
  12. { for folders, return true to scan contents }
  13. { for files return true if you delete the file - other changes to the file system would be bad... }
  14.         
  15.     function ScanDirectory (fs: FSSpec; doit: ScanProc): OSErr;
  16.  
  17. implementation
  18.  
  19.     uses
  20.         MyFileSystemUtils;
  21.  
  22.     function ScanDirectory (fs: FSSpec; doit: ScanProc): OSErr;
  23.         var
  24.             pb: CInfoPBRec;
  25.             ret, folder: boolean;
  26.             path: Str255;
  27.         procedure Scan (dirID: longint);
  28.             var
  29.                 index, len: integer;
  30.                 oe: OSErr;
  31.         begin
  32.             index := 1;
  33.             repeat
  34.                 with pb do begin
  35.                     oe := MyGetCatInfo(fs.vRefNum, dirID, fs.name, index, pb);
  36.                     index := index + 1;
  37.                     if oe = noErr then begin
  38.                         fs.parID := dirID;
  39.                         folder := BAND(pb.ioFlAttrib, ioDirMask) <> 0;
  40.                         ret := doit(fs, folder, path, pb);
  41.                         if folder and ret then begin
  42.                             len := length(path);
  43.                             path := concat(path, fs.name, ':');
  44.                             Scan(pb.ioDirID);
  45.                             path[0] := chr(len);
  46.                         end
  47.                         else if not folder and ret then begin
  48.                             index := index - 1;
  49.                         end;
  50.                     end;
  51.                 end;
  52.             until oe <> noErr;
  53.         end;
  54.         var
  55.             err: OSErr;
  56.             dummy: boolean;
  57.     begin
  58.         path := ':';
  59.         if fs.name <> '' then begin
  60.             err := MyGetCatInfo(fs.vRefNum, fs.parID, fs.name, 0, pb);
  61.             if err = noErr then begin
  62.                 if BAND(pb.ioFlAttrib, ioDirMask) <> 0 then begin
  63.                     Scan(pb.ioDirID);
  64.                 end
  65.                 else begin
  66.                     dummy := doit(fs, false, path, pb);
  67.                 end;
  68.             end;
  69.         end
  70.         else begin
  71.             Scan(fs.parID);
  72.             err := noErr;
  73.         end;
  74.         ScanDirectory := err;
  75.     end;
  76.  
  77. end.